//
//  makeJSONToRecord.m
//  JSONHelper
//
//  Created by David Blishen on 22/01/2011
//

#import "makeJSONFromRecord.h"

@implementation makeJSONFromRecord


- (id)performDefaultImplementation {
	
	NSDictionary	*asRecord;
	NSString		*result;
	AEMCodecs		*codecs = [[AEMCodecs alloc] init];
	

	// Use appscript framework to unpack the event into an object we can use
	
	asRecord =[codecs unpack:[self directParameter]];
	[codecs release];
	
	// Use the JSON framework to convert the object to JSON notation
	
	result = [asRecord JSONRepresentation];
		
	if (result==nil) {
		
		//We failed to create any valid JSON so return nothing
		NSLog(@"Failed to make JSON from: %@", asRecord);
		result=@"";
	}
		
	// Return the result to the applescript
	
	return result;
	
}

@end
